const config = require('./config.js');

/**
 * 上传图片
 * url:后端接口
 * type:场景，1新用户上传头像。2个人主页编辑照片
 * params:入参
 */

  const uploadFile =  function(url,type,params){

  var header = {
    'content-type': 'amultipart/form-data',  //form格式
  }
  //config.host + url
  //'https://www.bonaxl.com:8094/api/aboard/user/uploadAvtar'
  return new Promise((resolve, reject,next) => {
    wx.uploadFile({
      url: config.host + url,
      filePath: params.fileUpload,
      name: 'fileUpload',
      header,
      formData: params,
      success (res){
        console.log(res)
        const data = res.data
        if (res.statusCode == 200) {
          resolve()
        }
      }
    })

  })
  
}

//转化成小程序模板语言
module.exports = {
  uploadFile
};